package de.baumann.browser.views.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

public abstract class BaseDialog extends Dialog {
    protected Context mContext;

    public BaseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
        init();
    }

    public BaseDialog(@NonNull Context context) {
        super(context);
        this.mContext = context;
        init();
    }

    private void init(){
        setContentView(laoutId());
        initView();
        Window window = getWindow();
        assert window != null;
        window.setBackgroundDrawable(null);
        window.setDimAmount(getDimAmount());
        window.setGravity(gravity());
        window.getDecorView().setPadding(0, 0, 0, 0);

        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    protected abstract int laoutId();

    protected abstract void initView();

    protected int gravity() {
        return Gravity.CENTER;
    }

    protected float getDimAmount() {
        return 0.6f;
    }
}
